<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('盘点管理')"/>
    <style type="text/css">
        #inline-font {
            margin-right: 5px;
            font-size: 30px;
        }

        .element_container {
            width: 200px;
            display: inline-block;
        }
        div.popContainer {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.3);
            text-align: center;
        }
    </style>
</head>
<body class="gray-bg">
<div id="myVue">
    <div class="container-div" onmousemove="parent.updateTimeOut()">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                原箱号：<input type="text" name="boxCode"/>
                            </li>
                            <li>
                                当前箱号：<input type="text" name="toBoxCode"/>
                            </li>
<!--                            <li>-->
<!--                                托盘状态：-->
<!--                                <select name="boxState">-->
<!--                                    <option value="-1">不限</option>-->
<!--                                    <option value="0">不在货位上</option>-->
<!--                                    <option value="1">在货位上</option>-->
<!--                                    <option value="2">任务执行中(锁定)</option>-->
<!--                                </select>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                子库存组织：-->
<!--                                <select name="subInventoryId">-->
<!--                                    <option value="-1"></option>-->
<!--                                    <option value="1">待检</option>-->
<!--                                    <option value="2">基板一厂板材库</option>-->
<!--                                    <option value="3">基板一厂板材过期库</option>-->
<!--                                    <option value="4">基板一厂板材延期库</option>-->
<!--                                    <option value="5">基板一厂不合格库</option>-->
<!--                                    <option value="6">基板一厂责任待确认材料库</option>-->
<!--                                    <option value="7">基板一厂预测备料库</option>-->
<!--                                </select>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">

                <!-- 盘点 -->
                <a class="btn btn-danger btn-edit disabled" @click="updateType()"
                   v-if="operator.checkPermission == 2"
                   style="background-color: #00ceff;border-color: #00ceff;">
                    <i class="glyphicon glyphicon-log-in"></i> 确认盘点数量
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true" style="white-space:nowrap"></table>
            </div>
        </div>
    </div>
    <!-- 库内移动 -->
    <!--<el-dialog title="库内移动" :visible.sync="moveDialogVisible" width="35%">
        <el-form :model="move" label-width="120px">
            <el-form-item label="箱号">
                <el-input style="width: 80%"v-model="move.boxCode"/>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
&lt;!&ndash;                <el-button @click="qualityAbnormalDialogVisible = false">取 消</el-button>&ndash;&gt;
                <el-button type="primary" @click="wareHouseMoving(1)">移动至异常处理货位</el-button>
                <el-button type="primary" @click="wareHouseMoving(2)">移动至此箱原位</el-button>
        </span>
    </el-dialog>-->

    <!--盘点模态框-->
    <el-dialog title="盘点" :visible.sync="inventoryCheckDialogVisible" width="35%">
        <el-form :model="inventoryCheckOne" label-width="120px">
            <el-form-item label="类型">
                <el-select v-model="inventoryCheckOne.type" disabled="true" style="width: 80%;">
                    <el-option v-bind:value="1" label="手动盘点"></el-option>
                    <el-option v-bind:value="2" label="自动盘点"></el-option>
                </el-select>
            </el-form-item>
            <!--<el-form-item label="箱号">
                <el-input style="width: 80%" v-model="inventoryCheck.boxCode"/>
            </el-form-item>-->
            <el-form-item label="账户别名">
                <el-select v-model="inventoryCheckOne.dispositionId" style="width: 80%;">
                    <el-option v-for="accountAlias in accountAliass" v-bind:value="accountAlias.dispositionId"
                               v-bind:label="accountAlias.accountAlias"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="盘点数量">
                <el-input style="width: 80%" v-model="inventoryCheckOne.checkQuantity"/>
            </el-form-item>
            <el-form-item label="料号" v-if="inventoryCheckOne.type == 1">
                <el-input style="width: 80%" v-model="inventoryCheckOne.itemCode"/>
            </el-form-item>
            <el-form-item label="批次" v-if="inventoryCheckOne.type == 1">
                <el-input style="width: 80%" v-model="inventoryCheckOne.batch"/>
            </el-form-item>
            <el-form-item label="子库" v-if="inventoryCheckOne.type == 1">
                <el-select v-model="inventoryCheckOne.subInventoryId" style="width: 80%;">
                    <el-option v-for="subInventory in subInventorys"
                               v-bind:value="subInventory.subInventoryId"
                               v-bind:label="subInventory.subInventoryName"/>
                </el-select>
            </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
<!--                <el-button @click="subInventoryTransferDialogVisible = false">取 消</el-button>-->
                <el-button type="primary" @click="commitInventoryCheck()">确 定</el-button>
        </span>
    </el-dialog>

    <!-- 刷卡验证 -->
    <div class='popContainer'>
        <div style="margin: 10px;width:400px;margin:0 auto;height: 160px;text-align:center;
    background:white;margin-top:200px;border-radius: 10px;">
            <div style="width:400px;height: 30px;margin-top:10px">
                <span style="font-size:20px;margin-top:20px">登录</span>
            </div>
            <hr/>
            <div style="margin-top:20px;">
                <span id="inline-font">卡号:</span>
                <div class="element_container" style="width:200px;height:50px;">
                    <el-input placeholder="请输入卡号" @change="qwe" id="card" type="password" v-model="card"></el-input>
                </div>
            </div>
        </div>
    </div>
    <div th:include="include :: footer"></div>
</div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('in:boxItem:edit')}]];
    var removeFlag = [[${@permission.hasPermi('in:boxItem:remove')}]];
    var prefix = ctx + "inventoryCheck";

    function addBill() {
        var _url = prefix + "/add";
        $.modal.openFull("新增", _url);
    }

    $(function () {
        var options = {
            url: prefix + "/findList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail",
            modalName: "盘点管理",
            showExport: false,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'boxCode',
                    title: '原箱号',
                    sortable: true
                },
                {
                    field: 'quantity',
                    title: '原数量',
                    sortable: true
                },
                {
                    field: 'toBoxCode',
                    title: '当前箱号',
                    visible: true
                },
                {
                    field: 'itemCode',
                    title: '料号',
                    sortable: true
                },
                {
                    field: 'batch',
                    title: '批次',
                    sortable: true
                },

                {
                    field: 'afterCheckQuantity',
                    title: '盘点数量',
                    visible: true
                },
                {
                    field: 'checkQuantity',
                    title: '盘盈(+)/盘亏(-)',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value !== 0) {
                            actions.push("<span style='display: inline-block;line-height: 30px;padding: 0 10px;border: 1px solid #ff0e15;color: #070707;background-color: #ff0e15;'><!--待检-->"+row.checkQuantity+"</span>");
                        }
                        else{
                            actions.push("<span style='display: inline-block;line-height: 30px;padding: 0 10px;border: 1px solid #d9ecff;color: #434647;background-color: #F7F8FC;'><!--待检-->"+row.checkQuantity+"</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'state',
                    title: '状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value == 2) {
                            actions.push("<span style='display: inline-block;line-height: 30px;padding: 0 10px;border: 1px solid #d9ecff;color: #409eff;background-color: #ecf5ff;'>已完成</span>");
                        }
                        if (value == 1) {
                            actions.push("<span style='display: inline-block;line-height: 30px;padding: 0 10px;border: 1px solid #d9ecff;color: #FF2D3E;background-color: #FFAD7E;'>任务执行中</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'type',
                    title: '类型',
                    visible: true,
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (value === 1) {
                            actions.push("" +
                                "<span style='display: inline-block;line-height: 30px;padding: 0 10px;border: 1px solid #d9ecff;color: #434647;background-color: #fdff2d;'>手动盘点</span>");
                        }
                        if (value === 2) {
                            actions.push("<span style='display: inline-block;line-height: 30px;padding: 0 10px;border: 1px solid #d9ecff;color: #434647;background-color: #4499ff;'>自动盘点</span>");
                        }
                        return actions.join('');
                    }
                },
            ]
        };
        $.table.init(options);
    });
    var app = new Vue({
        el: '#myVue',
        data: {
            operator: '',
            card: '',
            loginPerson: '',
            loginPersonCardNo: '',
            taskStartTime: '',

            accountAliass: [],
            subInventorys:[],

            moveDialogVisible: false,
            move:{
                boxCode:'',
            },

            inventoryCheckDialogVisible:false,
            inventoryCheckOne:{
                type:'',
                dispositionId:'',
                checkQuantity:'',
                itemCode:'',
                batch:'',
                subInventoryId:'',
            },
        },
        methods: {
            //退出
            /*exit:function(){
                let that = this;
                that.clearParams();
                that.loginPerson='';
                that.loginPersonCardNo='';
                document.querySelector('.popContainer').style.display = 'block';
                document.querySelector('body').style.overflow = 'hidden';
                $('#card').focus();
            },*/

            //刷卡验证（ok）
            qwe: function () {
                let that = this;
                if (that.card == '' || that.card == null) {
                    alert("请刷卡登陆！");
                    return false
                }
                let card = {
                    card: that.card,
                }
                $.modal.loading("验证中，请稍后");
                $.ajax({
                    type: "post",
                    url: "/system/operator/findByCard",
                    data: JSON.stringify(card),
                    dataType: "json",
                    contentType: "application/json;charset-UTF-8",
                    async: false,
                    error: function (data) {
                        $.modal.msgError("系统错误");
                        $.modal.closeLoading();
                    },
                    success: function (data) {
                        $.modal.closeLoading();
                        if (data.code === 200) {
                            that.taskStartTime = that.date;
                            that.loginPerson = data.data.operatorName + data.data.empNo;
                            that.loginPersonCardNo = data.data.operatorCard;
                            that.card = '';
                            that.operator = data.data;
                            document.querySelector('.popContainer').style.display = 'none';
                        } else {
                            $.modal.msgError("系统无此账户,请联系管理员！");
                        }
                    },
                });
            },

            updateType:function(){
                let that = this;
                var rows = $('#bootstrap-table').bootstrapTable('getAllSelections');
                if(rows[0].state === 2){
                    $.modal.msgError("此盘点单已完成");
                    return false;
                }
                that.inventoryCheckOne.type = rows[0].type;
                that.inventoryCheckDialogVisible=true;
            },
            //盘点确认（完成）
            commitInventoryCheck: function () {
                let that = this;
                var rows = $('#bootstrap-table').bootstrapTable('getAllSelections');
                if(rows[0].state === 2){
                    $.modal.msgError("此盘点单已完成");
                    return false;
                }
                if(that.isNull(that.inventoryCheckOne.dispositionId)){
                    $.modal.msgError("请选择账户别名！");
                    return false;
                }
                if(that.isNull(that.inventoryCheckOne.checkQuantity)){
                    $.modal.msgError("盘点数量不可为空");
                    return false;
                }
                if(that.inventoryCheckOne.type === 1 && that.isNull(that.inventoryCheckOne.itemCode)){
                    $.modal.msgError("料号不可为空");
                    return false;
                }
                if(that.inventoryCheckOne.type === 1 && that.isNull(that.inventoryCheckOne.batch)){
                    $.modal.msgError("批次不可为空");
                    return false;
                }
                if(that.inventoryCheckOne.type === 1 && that.isNull(that.inventoryCheckOne.subInventoryId)){
                    $.modal.msgError("子库不可为空");
                    return false;
                }
                if(that.inventoryCheckOne.checkQuantity < 0){
                    $.modal.msgError("盘点数量请填写正整数");
                    return false;

                }
                that.inventoryCheckDialogVisible = false;
                $.modal.loading("处理中，请稍等！");
                var list = {
                    loginPersonCardNo: that.loginPersonCardNo,
                    type: that.inventoryCheckOne.type,
                    inventoryCheckId: rows[0].inventoryCheckId,
                    dispositionId: that.inventoryCheckOne.dispositionId,
                    checkQuantity: that.inventoryCheckOne.checkQuantity,
                    itemCode:that.inventoryCheckOne.itemCode,
                    batch:that.inventoryCheckOne.batch,
                    subInventoryId: that.inventoryCheckOne.subInventoryId,
                }
                $.ajax({
                    type: "post",
                    url: "/inventoryCheck/inventoryCheck",
                    data: JSON.stringify(list),
                    dataType: "json",
                    contentType: "application/json;charset-UTF-8",
                    /*async: true,*/
                    error: function (data) {
                        $.modal.msgError("系统错误，请联系管理员");
                        $.modal.closeLoading();
                    },
                    success: function (data) {
                        $.modal.closeLoading();
                        if (data.code == 200) {
                            $.modal.msgSuccess("盘点成功！");
                            that.inventoryCheckOne.type='';
                            that.inventoryCheckOne.dispositionId='';
                            that.inventoryCheckOne.checkQuantity='';
                            that.inventoryCheckOne.itemCode='';
                            that.inventoryCheckOne.batch='';
                            that.inventoryCheckOne.subInventoryId='';
                            $.table.refresh();
                        } else {
                            that.inventoryCheckDialogVisible = true;
                            $.modal.msgError(data.msg);
                        }
                    }
                });
            },


            //遮罩层
            showOverlay(content) {
                let that = this;
                let text = '';
                if (content) {
                    text = content
                }
                that.loading = that.$loading({
                    lock: true,
                    text: text || '',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
            },
            hideOverlay() {
                let that = this;
                if (that.loading) {
                    that.loading.close();
                }
            },

            isNull: function (param) {
                if (param === null || param === undefined || param === '') {
                    return true;
                }
                return false;
            }
        },
        created: function () {
            let that = this;
            //获取账户别名
            $.ajax({
                type: "post",
                url: "/accountAlias/findAccountAliasList",
                data: JSON.stringify({keyWords:"盘点"}),
                dataType: "json",
                contentType: "application/json;charset-UTF-8",
                async: false,
                error: function (data) {
                    $.modal.msgError("系统错误");
                },
                success: function (data) {
                    if (data.code === 200) {
                        that.accountAliass = data.data;
                    } else {
                        $.modal.msgError("获取账户别名失败,请刷新或者联系管理员！");
                    }
                },
            });
            //获取子库
            $.ajax({
                type: "post",
                url: "/subInventory/findIdNotEqualOne",
                data: JSON.stringify(),
                dataType: "json",
                contentType: "application/json;charset-UTF-8",
                async: false,
                error: function (data) {
                    $.modal.msgError("系统错误");
                },
                success: function (data) {
                    if (data.code === 200) {
                        that.subInventorys = data.data;
                    } else {
                        $.modal.msgError("系统无此子库,请联系管理员！");
                    }
                },
            });
        },
        mounted: function () {
            $('#card').focus();
        },
    })
</script>
</body>
</html>